package com.bcinfo.iccard.admin.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * @ClassName TxtUtil
 * @Description TODO
 * 
 * @author tonic
 * @date 2013-12-13 下午2:04:53
 * 
 * @Code_Examples <PRE>
 * TODO
 * </PRE>
 * 
 * 
 */
public class TxtUtil
{
    public static List<String> readTxtFile(String filePath)
    {
        List<String> result = new ArrayList<String>();
        try
        {
            String encoding = "utf-8";
            File file = new File(filePath);
            if (file.isFile() && file.exists())
            { // 判断文件是否存在
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null)
                {
                    if (StringUtils.isNotBlank(lineTxt))
                    {
                        result.add(lineTxt);
                    }
                }
                read.close();
            }
            else
            {
                System.out.println("找不到指定的文件");
            }
        }
        catch (Exception e)
        {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
        return result;
    }

    public static void main(String argv[])
    {
        String filePath = "d:\\test.txt";
        List<String> str =readTxtFile(filePath);
        for(String s:str){
            System.out.println(s);
        }
    }
}
